import "../css/CalColumn-DOVlLPd3.css";
import { defineComponent as Z, toRefs as ee, ref as p, watch as q, openBlock as w, createElementBlock as K, createVNode as s, unref as l, isRef as le, withCtx as i, createElementVNode as f, createTextVNode as x, toDisplayString as g, createCommentVNode as G, computed as te, reactive as J, onMounted as ae, createBlock as P } from "vue";
import { r as oe, e as z, H as Q, b1 as W, c as H, b as M, a as X, aX as ne, B as se, C as j, aY as ie, D as re, o as de, f as A } from "./vendor.CF2kwqqq.js";
import { C as ue } from "./main.DDNsfpKl.js";
import { _ as ce } from "./_plugin-vue_export-helper.CHgC5LLL.js";
import { d as $, b as pe, e as fe } from "./index.Bbfhrq76.js";
const me = [
  {
    name: "四则运算函数",
    children: [
      {
        name: "+"
      },
      {
        name: "-"
      },
      {
        name: "*"
      },
      {
        name: "/"
      }
    ]
  }
], ve = ["int", "long", "short", "float", "double"], he = { class: "nifi-calculate-field" }, _e = { class: "field-name" }, be = {
  class: "field_content",
  "h-468": ""
}, Ve = { class: "fun_tree" }, ge = { class: "custom-tree-node" }, xe = { class: "multi-ellipsis" }, ke = { key: 0 }, Ce = { class: "fun_tree field_tree" }, De = { class: "custom-tree-node" }, ye = { class: "multi-ellipsis" }, Ne = { key: 0 }, Fe = { class: "field_body" }, Ee = { class: "field_top" }, Re = { class: "field_bottom" }, Te = { class: "field_footer" }, we = /* @__PURE__ */ Z({
  __name: "Dialog",
  props: {
    modelValue: { type: Boolean },
    fieldData: {},
    inputValue: {}
  },
  emits: ["update:modelValue", "handleUpdateValue"],
  setup(k, { emit: N }) {
    const h = N, L = k, { modelValue: S, fieldData: F, inputValue: U } = ee(L), C = p(), O = p(), r = p(), d = p(""), c = p(""), _ = p([
      {
        name: "字段",
        children: U.value
      }
    ]), D = p("从左侧列表选择或直接输入函数、字段"), b = p(F.value.fieldName), E = p(F.value.expression), R = {
      children: "children",
      label: "name"
    }, B = (t, a) => {
      var e;
      a.isLeaf && ((e = C.value) == null || e.insertValue(t.name));
    }, u = (t, a) => {
      var e;
      if (a.isLeaf) {
        if (!ve.includes(t == null ? void 0 : t.type.toLowerCase())) {
          D.value = "所选字段需是数值类型的字段";
          return;
        }
        (e = C.value) == null || e.insertValue(t.name), D.value = "从左侧列表选择或直接输入函数、字段";
      }
    }, y = () => {
      h("update:modelValue", !1);
    }, v = () => {
      var a;
      if (!b.value) {
        X.error("字段名不可为空");
        return;
      }
      let t = (a = C.value) == null ? void 0 : a.getValue();
      if (t === "") {
        X.error("表达式不可为空");
        return;
      }
      h("handleUpdateValue", {
        ...F.value,
        fieldName: b.value,
        expression: t
      }), y();
    };
    q(d, (t) => {
      O.value.filter(t);
    });
    const T = (t, a) => t ? a.name.includes(t) : !0;
    q(c, (t) => {
      r.value.filter(t);
    });
    const I = (t, a) => t ? a.name.includes(t) : !0;
    return (t, a) => (w(), K("div", he, [
      s(l(oe), {
        modelValue: l(S),
        "onUpdate:modelValue": a[3] || (a[3] = (e) => le(S) ? S.value = e : null),
        title: "新增字段",
        "destroy-on-close": "",
        "w-900": "",
        "before-close": y
      }, {
        default: i(() => [
          f("div", _e, [
            x(" 新增字段名 "),
            s(l(z), {
              modelValue: b.value,
              "onUpdate:modelValue": a[0] || (a[0] = (e) => b.value = e)
            }, null, 8, ["modelValue"])
          ]),
          f("div", be, [
            f("div", Ve, [
              s(l(z), {
                modelValue: d.value,
                "onUpdate:modelValue": a[1] || (a[1] = (e) => d.value = e),
                placeholder: "搜索函数",
                "prefix-icon": l(Q)
              }, null, 8, ["modelValue", "prefix-icon"]),
              s(l(W), {
                ref_key: "funTreeRef",
                ref: O,
                "default-expand-all": "",
                data: l(me),
                props: R,
                onNodeClick: B,
                "filter-node-method": T
              }, {
                default: i(({ node: e, data: o }) => [
                  f("div", ge, [
                    s(l(H), null, {
                      content: i(() => [
                        x(g(e.label), 1)
                      ]),
                      default: i(() => [
                        f("div", xe, g(e.label), 1)
                      ]),
                      _: 2
                    }, 1024),
                    o.children && o.children.length > 0 ? (w(), K("span", ke, " (" + g(o.children.length) + ") ", 1)) : G("", !0)
                  ])
                ]),
                _: 1
              }, 8, ["data"])
            ]),
            f("div", Ce, [
              s(l(z), {
                modelValue: c.value,
                "onUpdate:modelValue": a[2] || (a[2] = (e) => c.value = e),
                placeholder: "搜索字段",
                "prefix-icon": l(Q)
              }, null, 8, ["modelValue", "prefix-icon"]),
              s(l(W), {
                ref_key: "fieldTreeRef",
                ref: r,
                "default-expand-all": "",
                data: _.value,
                props: R,
                onNodeClick: u,
                "filter-node-method": I
              }, {
                default: i(({ node: e, data: o }) => [
                  f("div", De, [
                    s(l(H), null, {
                      content: i(() => [
                        x(g(e.label), 1)
                      ]),
                      default: i(() => [
                        f("div", ye, g(e.label), 1)
                      ]),
                      _: 2
                    }, 1024),
                    o.children && o.children.length > 0 ? (w(), K("span", Ne, " (" + g(o.children.length) + ") ", 1)) : G("", !0)
                  ])
                ]),
                _: 1
              }, 8, ["data"])
            ]),
            f("div", Fe, [
              f("div", Ee, [
                s(ue, {
                  ref_key: "codeEditorRef",
                  ref: C,
                  "model-value": E.value
                }, null, 8, ["model-value"])
              ]),
              f("div", Re, g(D.value), 1)
            ])
          ]),
          f("div", Te, [
            s(l(M), { onClick: y }, {
              default: i(() => [
                x("取消")
              ]),
              _: 1
            }),
            s(l(M), {
              type: "primary",
              onClick: v
            }, {
              default: i(() => [
                x("保存")
              ]),
              _: 1
            })
          ])
        ]),
        _: 1
      }, 8, ["modelValue"])
    ]));
  }
}), Se = { class: "multi-ellipsis" }, Ue = /* @__PURE__ */ Z({
  __name: "index",
  props: {
    formdata: {},
    graphShadow: {},
    inputV: {},
    expression: {},
    newField: {},
    step: {}
  },
  setup(k) {
    const N = k, { formdata: h, inputV: L, step: S, expression: F, newField: U, graphShadow: C } = ee(N);
    let O = te(() => S.value === "running");
    const r = p(), d = p(L.value), c = p(!1), _ = p(), D = p(0), b = () => {
      u.tableData.push({
        fieldName: "",
        expression: "",
        prompt: ""
      });
    }, E = (e, o) => {
      _.value = e, D.value = o, c.value = !0;
    }, R = (e) => {
      u.tableData[D.value] = e;
    }, B = (e) => {
      u.tableData.splice(e, 1);
    }, u = J({
      tableData: []
    });
    F.value.length > 0 && U.value.length > 0 && (u.tableData = U.value.map((e, o) => ({
      fieldName: U.value[o],
      expression: F.value[o],
      prompt: "",
      visible: !1
    })));
    const y = (e, o, n) => {
      if (o === "")
        return n(new Error("字段名不能为空"));
      if (u.tableData.filter((V) => V.fieldName === o).length > 1)
        return n(new Error("不可与其他字段重名"));
      n();
    }, v = p(), T = J({
      fieldName: [
        {
          // required: true,
          // message: "字段名不能为空",
          validator: y,
          trigger: "blur"
        }
      ]
      // expression: [
      //   {
      //     required: true,
      //     message: "字段值不能为空",
      //     trigger: "blur",
      //   },
      // ],
    }), I = (e, o) => {
      if (e) {
        if (e.prompt = "", e.visible = !1, e.fieldName === "") {
          e.prompt = "字段名不能为空", e.visible = !0;
          return;
        }
        for (let n = 0; n < u.tableData.length; n++)
          if (u.tableData[n].fieldName === e.fieldName && n !== o) {
            e.prompt = "不可与其他新增字段重名", e.visible = !0;
            return;
          }
        e.prompt = "", e.visible = !1;
      }
    }, t = (e) => {
      e && (e.prompt = "", e.visible = !1);
    };
    ae(() => {
      C.value.set(h.value.id, "checkForm", a), C.value.set(h.value.id, "tableData", u.tableData);
    });
    const a = () => new Promise((e) => {
      var o;
      (o = v.value) == null || o.validate((n, m) => {
        n ? e(u.tableData) : (X.error(Object.values({ ...m })[0][0].message), e(!1));
      });
    });
    return (e, o) => (w(), K("div", {
      class: "nifi-calculate",
      ref_key: "calculateRef",
      ref: r
    }, [
      x(" 新增字段 "),
      s(l(M), {
        type: "primary",
        onClick: b,
        style: { "margin-left": "12px" }
      }, {
        default: i(() => [
          x(" 新增字段 ")
        ]),
        _: 1
      }),
      s(l(ne), {
        ref_key: "formRef",
        ref: v,
        model: u,
        rules: T,
        "label-width": "108px",
        inline: !0,
        disabled: l(O)
      }, {
        default: i(() => [
          s(l(se), {
            data: u.tableData,
            "max-height": "400",
            "row-style": { height: "45px" },
            "header-cell-style": {
              backgroundColor: "#F8F9FC",
              borderColor: "transparent"
            }
          }, {
            default: i(() => [
              s(l(j), { label: "字段名" }, {
                default: i(({ $index: n, row: m }) => [
                  s(l(ie), {
                    prop: "tableData." + n + ".fieldName",
                    rules: T.fieldName
                  }, {
                    default: i(() => [
                      s(l(H), {
                        effect: "customized",
                        content: m.prompt,
                        visible: m.visible
                      }, {
                        default: i(() => [
                          s(l(z), {
                            modelValue: m.fieldName,
                            "onUpdate:modelValue": (V) => m.fieldName = V,
                            placeholder: "请输入",
                            class: "item__input",
                            clearable: "",
                            onBlur: (V) => {
                              var Y;
                              return m.fieldName = (Y = V.target) == null ? void 0 : Y.value.trim();
                            },
                            onMouseenter: (V) => I(m, n),
                            onMouseleave: (V) => t(m)
                          }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur", "onMouseenter", "onMouseleave"])
                        ]),
                        _: 2
                      }, 1032, ["content", "visible"])
                    ]),
                    _: 2
                  }, 1032, ["prop", "rules"])
                ]),
                _: 1
              }),
              s(l(j), {
                label: "字段值",
                width: "300"
              }, {
                default: i(({ row: n, $index: m }) => [
                  n.expression ? (w(), P(l(H), { key: 0 }, {
                    content: i(() => [
                      x(g(n.expression), 1)
                    ]),
                    default: i(() => [
                      f("div", Se, [
                        f("div", null, g(n.expression), 1),
                        s(l(M), {
                          icon: l(re),
                          onClick: (V) => E(n, m)
                        }, null, 8, ["icon", "onClick"])
                      ])
                    ]),
                    _: 2
                  }, 1024)) : (w(), P(l(M), {
                    key: 1,
                    type: "primary",
                    link: "",
                    onClick: (V) => E(n, m)
                  }, {
                    default: i(() => [
                      x(" 添加字段值 ")
                    ]),
                    _: 2
                  }, 1032, ["onClick"]))
                ]),
                _: 1
              }),
              s(l(j), { label: "操作" }, {
                default: i(({ $index: n }) => [
                  s(l(M), {
                    icon: l(de),
                    onClick: () => B(n)
                  }, null, 8, ["icon", "onClick"])
                ]),
                _: 1
              })
            ]),
            _: 1
          }, 8, ["data"])
        ]),
        _: 1
      }, 8, ["model", "rules", "disabled"]),
      c.value ? (w(), P(we, {
        key: 0,
        modelValue: c.value,
        "onUpdate:modelValue": o[0] || (o[0] = (n) => c.value = n),
        fieldData: _.value,
        inputValue: d.value,
        onHandleUpdateValue: R
      }, null, 8, ["modelValue", "fieldData", "inputValue"])) : G("", !0)
    ], 512));
  }
}), Be = /* @__PURE__ */ ce(Ue, [["__scopeId", "data-v-24aa513e"]]), ze = () => {
  let k = [], N = [], h = [];
  const L = ["output-param", "output字段（自动填入）"];
  return { name: ["org.apache.nifi.column.processors.CalColumn_2_0"], excludeKeys: ["new-field", "expression", "output-param"], selfFormColumn: [
    {
      tag: Be,
      // propInput: "config.properties['col-selector-input']",
      // propOutput: "config.properties['output-param']",
      ":formdata": "formData",
      setup({ params: r }) {
        return {
          inputV: k,
          expression: N,
          newField: h,
          step: r.step.value,
          graphShadow: r.graphShadow
        };
      },
      ":inputV": "inputV",
      ":expression": "expression",
      ":newField": "newField",
      ":step": "step",
      ":graphShadow": "graphShadow"
    }
  ], hooksOpen: (r, d) => {
    k = [], N = [], h = [];
    let { source: c } = d.event, _ = c.get(r.id).component.config.properties;
    N = $(_.expression), h = $(_["new-field"]), k = pe(r, d, L);
  }, hooksSubmit: (r, d) => {
    var b, E, R, B, u, y;
    fe(r, d);
    let c = ((b = d.event.shadow) == null ? void 0 : b.get(r.id).tableData) ?? [], _ = c.filter((v) => v.fieldName === ""), D = new Set(c.map((v) => v.fieldName));
    if (_.length > 0)
      throw (E = d.event.shadow) == null || E.get(r.id).checkForm(), new Error("字段名不能为空");
    if (D.size !== c.length)
      throw (R = d.event.shadow) == null || R.get(r.id).checkForm(), new Error("不可与其他字段重名");
    {
      let v = [], T = [], I = [...k], t = (B = d.event.form) == null ? void 0 : B.data.value[r.id].config.properties;
      c.forEach((a) => {
        v.push(a.expression), T.push(a.fieldName), I.push({
          doc: "",
          name: a.fieldName,
          originalValue: "",
          type: "STRING"
        });
      }), A(t, "expression", $(v)), A(t, "new-field", $(T)), A(t, "output-param", $(I)), (u = d.event.shadow) == null || delete u.get(r.id).tableData, (y = d.event.shadow) == null || delete y.get(r.id).checkForm;
    }
  } };
};
export {
  ze as default
};
